function [e,tran] = sTauchen(rho,miu,sigmau,ndiv,m);
% Simple way to discretize from Tauchen
% create a transition matrix for an AR(1) process
% e(t) = mu(1-rho)+ rho* e(t-1) + sigmau*u(t)   where u ~ N(0,1)

esig = (sigmau^2/(1-rho^2))^0.5;

% Have the range of e within m standard deviations
e = (-m*esig+miu):((2*m*esig)/(ndiv-1)):(m*esig+miu);
ne = length(e);

tran = zeros(ne,ne);
for j = 1:ne;  % j is the current state
 for k = 1:ne; % k is the future state
  if k==1;
   w = e(k+1)-e(k);
   tran(j,k) = normcdf((e(k)-miu-rho*(e(j)-miu)+w/2)/sigmau);
  elseif k==ne;
   w = e(k)-e(k-1);
   tran(j,k) = 1-normcdf((e(k)-miu-rho*(e(j)-miu)-w/2)/sigmau);
  else
   w = e(k)-e(k-1);
   tran(j,k) = normcdf((e(k)-miu-rho*(e(j)-miu)+w/2)/sigmau) - normcdf((e(k)-miu-rho*(e(j)-miu)-w/2)/sigmau);
  end
 end
end


%e = exp(e);  % our idio shocks will be log normal with mean=1;


